<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta name="viewport"content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes"/>
    <meta charset="UTF-8">
    <title>词汇测试--个人信息登记</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>

    <style type="text/css">

        body{
            position: relative;
            height: 600px;
            background-image: url(../static/images/page1.9.jpg);
            background-repeat: no-repeat;
            background-color: #008081;
        }
        .data{
            /* background-color: rgb(0, 0, 0); */
            width: 303px;
            height: 40px;
            margin: 8px auto;
            border: solid 5px;
            border-radius: 5px;
            border-color: rgb(0,0,0);
            /* color: white; */
            font-size: 20px;
        }
        #cet4,#cet6{
            width: 303px;
        }
        #submit {
            width: 160px;
            height: 80px;
            position: relative;
            top: 315px;
            left: 1231px;
        }
        .box {
            position: relative;
            left: 700px;
            top: 355px;
            width: 460px;
            height: 165px;
        }


        #zhuce{
            width: 160px;
            height: 80px;
            position: relative;
            background-image: url(../static/images/page1.23.png);
            background-repeat: no-repeat;
            position: relative;
            top: 201px;
            left: 1066px;
        }

        /* background-color: white;
    }

         */

</style>

</head>

<body>
<form id="form">
    <div class="box" style="font-size:45px;font-family:'仿宋';>
        <!-- autocomplete="off 关闭自动填充 -->
        学号：<input type="text" name="sid" id="sid"  class="data" required autocomplete="off"><br>

<!--        姓名：<input type="text" name="username" id="username"   class="data" required autocomplete="off"><br>-->

        密码：<input type="password" name="password" id="password"   class="data" required autocomplete="off"><br>

        cet4：<input type="number" name="cet4" id="cet4"   class="data" required autocomplete="off" min="0" max="710"><br>

        cet6：<input type="number" name="cet6" id="cet6"  class="data" required autocomplete="off" min="0" max="710"><br>
    </div>
    <input type="image" value="提交" id="submit" src="../static/images/page1.22.png" onclick="getInformation()">
    <input type="image" id="zhuce" onclick="toRegister()" src="../static/images/page1.23.png">
</form>
<script>
    function toRegister(){
        window.location.href="register";
    }

    function getInformation(){
        let json = {"code":200,"msg":"get test"};

        var user = {
            "uid": document.getElementById("sid").value,
            // "username":  document.getElementById("username").value,
            "password": document.getElementById("password").value,
            "cet4": document.getElementById("cet4").value,
            "cet6": document.getElementById("cet6").value
        };

        $("form").submit(function() {
            //传到后台
            $.ajax({
                type: 'POST',
                url: 'tologin',
                data: JSON.stringify(user),
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (resJson) {
                    if(resJson['flag']=="success")
                    {
                        sessionStorage.setItem("username", resJson['user'].username);
                        sessionStorage.setItem("uid", resJson['user'].uid);
                        sessionStorage.setItem("cet4", resJson['user'].cet4);
                        sessionStorage.setItem("cet6", resJson['user'].cet6);
                        // addCookie("id",data['data']['id'],0);
                        window.location.href="first";
                    }
                    else if(resJson['flag']=="fail")
                    {
                        alert("账号或密码有误！");
                        window.location.href="login";
                    }
                },
                error: function () {
                    // window.location.href="login.html";
                }
            });
            return false;//阻止表单提交
        })
    };
    function addCookie(objName, objValue, objHours) {
        var str = objName + "=" + escape(objValue); //编码
        if (objHours > 0) {//为0时不设定过期时间，浏览器关闭时cookie自动消失
            var date = new Date();
            var ms = objHours * 3600 * 1000;
            date.setTime(date.getTime() + ms);
            str += "; expires=" + date.toGMTString();
        }
        document.cookie = str;
    }

</script>

</body>
</html>
